package ebusiness.ebusiness.Controllers;

import ebusiness.ebusiness.Dao.OrderDao.OrderQueryVO;
import ebusiness.ebusiness.Entity.Order;
import ebusiness.ebusiness.Entity.OrderDetail;
import ebusiness.ebusiness.Entity.UserEntity.Person;
import ebusiness.ebusiness.Entity.UserEntity.User;
import ebusiness.ebusiness.Entity.bigOrder;
import ebusiness.ebusiness.Mapper.PathUtil.PagePath;
import ebusiness.ebusiness.Mapper.PathUtil.WebPath;
import ebusiness.ebusiness.Models.Front.OrderSearch.OrderFrontManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class OrderSearchController {
    @RequestMapping(path = WebPath.USERORDERSEARCHLIST1,method = RequestMethod.GET)
    public String FindOrder(Model model, HttpSession session){



        try {
            Object obj=session.getAttribute("user");
            if(obj==null) return PagePath.SHOWORDERS;
            int id=(int)obj;
            OrderQueryVO orderQueryVO=new OrderQueryVO();
            List<Order> orders   =orderQueryVO.findOrderByUId(id);
            String msg= (String) session.getAttribute("msg");
            if(msg!=null)model.addAttribute(msg);





            model.addAttribute("orders",orders);
            System.out.println(orders);

        }catch (Exception e){
e.printStackTrace();
        }
        return PagePath.SHOWORDERS;
    }
   @RequestMapping(path = WebPath.USERORDERSEARCHLIST2,method = RequestMethod.GET)
    public String FindOrder2(Model model, HttpSession session,String id2,String day2){

       try {
           int id=Integer.valueOf(id2);
           int day=Integer.valueOf(day2);
           OrderQueryVO orderQueryVO=new OrderQueryVO();
           List<Order> orders   =orderQueryVO.findOrderByUId(id,day);
           model.addAttribute("orders",orders);
       }catch (Exception e){

       }
       return PagePath.SHOWORDERS;
    }
    @RequestMapping(path = WebPath.USERORDERSEARCHLIST3,method = RequestMethod.GET)
    public String FindOrder3(Model model, HttpSession session, int id, Date from,Date to){
        List<Order> orders= OrderFrontManager.UserSearch(id,from,to);
        model.addAttribute("orders",orders);
        return PagePath.SHOWORDERS;
    }
    @RequestMapping(path = WebPath.ADMINSEARCHORDER,method = RequestMethod.POST)
    public String AdminFindOrder(Model model, HttpSession session, int id, Date from,Date to) throws Exception{
        Person person=(Person) session.getAttribute("admin");
        List<Order> orders= null;

        return PagePath.SHOWORDERS;
    }



}
